package pile.pay.controller;

import com.alipay.api.AlipayApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pile.pay.config.alipayConfig.AlipayTradeEntity;
import pile.pay.entity.ResponseResult;
import pile.pay.service.IAliPayService;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Description:
 **/

@RestController
@RequestMapping("/alipay")
@Api(tags = {"支付宝支付接口详情"})
public class AliPayController {

    @Autowired
    private IAliPayService aliasPayService;

    /**
     * 统一下单-统一接口
     */
    @PostMapping("/transactions")
    @ApiOperation(value = "统一下单", notes = "前端菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public ResponseResult transactions(@Validated @RequestBody AlipayTradeEntity alipayTradeEntity) throws AlipayApiException {
        return aliasPayService.transactions(alipayTradeEntity);
    }

    /**
     * 支付回调
     */
    @PostMapping("/payNotify")
    @ApiOperation(value = "支付宝支付回调", notes = "前端菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public String payNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException {
        return aliasPayService.payNotify(request,response);
    }


    /**
     * 支付宝申请退款
     */
    @PostMapping("/refunds")
    @ApiOperation(value = "支付宝申请退款", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public ResponseResult refunds() {
        return aliasPayService.refunds();
    }





}